
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>声明合并 · TypeScript Handbook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Patrick Zhong">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Writing Definition Files.html" />
    
    
    <link rel="prev" href="Module Resolution.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="tutorials/">
            
                <a href="tutorials/">
            
                    
                    快速上手
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="tutorials/TypeScript in 5 minutes.html">
            
                <a href="tutorials/TypeScript in 5 minutes.html">
            
                    
                    5分钟了解TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="tutorials/ASP.NET Core.html">
            
                <a href="tutorials/ASP.NET Core.html">
            
                    
                    ASP.NET Core
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="tutorials/ASP.NET 4.html">
            
                <a href="tutorials/ASP.NET 4.html">
            
                    
                    ASP.NET 4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="tutorials/Gulp.html">
            
                <a href="tutorials/Gulp.html">
            
                    
                    Gulp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="tutorials/Knockout.html">
            
                <a href="tutorials/Knockout.html">
            
                    
                    Knockout.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="tutorials/React & Webpack.html">
            
                <a href="tutorials/React & Webpack.html">
            
                    
                    React与webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="tutorials/React.html">
            
                <a href="tutorials/React.html">
            
                    
                    React
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="tutorials/Angular 2.html">
            
                <a href="tutorials/Angular 2.html">
            
                    
                    Angular 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="tutorials/Migrating from JavaScript.html">
            
                <a href="tutorials/Migrating from JavaScript.html">
            
                    
                    从JavaScript迁移到TypeScript
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    手册
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="Basic Types.html">
            
                <a href="Basic Types.html">
            
                    
                    基础类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Variable Declarations.html">
            
                <a href="Variable Declarations.html">
            
                    
                    变量声明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="Interfaces.html">
            
                <a href="Interfaces.html">
            
                    
                    接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="Classes.html">
            
                <a href="Classes.html">
            
                    
                    类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="Functions.html">
            
                <a href="Functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="Generics.html">
            
                <a href="Generics.html">
            
                    
                    泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="Enums.html">
            
                <a href="Enums.html">
            
                    
                    枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="Type Inference.html">
            
                <a href="Type Inference.html">
            
                    
                    类型推论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="Type Compatibility.html">
            
                <a href="Type Compatibility.html">
            
                    
                    类型兼容性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="Advanced Types.html">
            
                <a href="Advanced Types.html">
            
                    
                    高级类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="Utilit Types.md">
            
                <span>
            
                    
                    实用工具类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="Symbols.html">
            
                <a href="Symbols.html">
            
                    
                    Symbols
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="Iterators and Generators.html">
            
                <a href="Iterators and Generators.html">
            
                    
                    Iterators 和 Generators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.14" data-path="Modules.html">
            
                <a href="Modules.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.15" data-path="Namespaces.html">
            
                <a href="Namespaces.html">
            
                    
                    命名空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.16" data-path="Namespaces and Modules.html">
            
                <a href="Namespaces and Modules.html">
            
                    
                    命名空间和模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.17" data-path="Module Resolution.html">
            
                <a href="Module Resolution.html">
            
                    
                    模块解析
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.18" data-path="Declaration Merging.html">
            
                <a href="Declaration Merging.html">
            
                    
                    声明合并
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.19" data-path="Writing Definition Files.html">
            
                <a href="Writing Definition Files.html">
            
                    
                    书写.d.ts文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.20" data-path="JSX.html">
            
                <a href="JSX.html">
            
                    
                    JSX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.21" data-path="Decorators.html">
            
                <a href="Decorators.html">
            
                    
                    Decorators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.22" data-path="Mixins.html">
            
                <a href="Mixins.html">
            
                    
                    混入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.23" data-path="Triple-Slash Directives.html">
            
                <a href="Triple-Slash Directives.html">
            
                    
                    三斜线指令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.24" data-path="Type Checking JavaScript Files.html">
            
                <a href="Type Checking JavaScript Files.html">
            
                    
                    JavaScript文件里的类型检查
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="declaration files/Introduction.html">
            
                <a href="declaration files/Introduction.html">
            
                    
                    如何书写声明文件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="declaration files/Library Structures.html">
            
                <a href="declaration files/Library Structures.html">
            
                    
                    结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="declaration files/Do's and Don'ts.html">
            
                <a href="declaration files/Do's and Don'ts.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="declaration files/By Example.html">
            
                <a href="declaration files/By Example.html">
            
                    
                    举例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="declaration files/Deep Dive.html">
            
                <a href="declaration files/Deep Dive.html">
            
                    
                    深入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="declaration files/Publishing.html">
            
                <a href="declaration files/Publishing.html">
            
                    
                    发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="declaration files/Consumption.html">
            
                <a href="declaration files/Consumption.html">
            
                    
                    使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    工程配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    tsconfig.json
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="Project References.html">
            
                <a href="Project References.html">
            
                    
                    工程引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Typings for NPM Packages.html">
            
                <a href="Typings for NPM Packages.html">
            
                    
                    NPM包的类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="Compiler Options.html">
            
                <a href="Compiler Options.html">
            
                    
                    编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="Configuring Watch.html">
            
                <a href="Configuring Watch.html">
            
                    
                    配置 Watch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="Compiler Options in MSBuild.html">
            
                <a href="Compiler Options in MSBuild.html">
            
                    
                    在MSBuild里使用编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="Integrating with Build Tools.html">
            
                <a href="Integrating with Build Tools.html">
            
                    
                    与其它构建工具整合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="Nightly Builds.html">
            
                <a href="Nightly Builds.html">
            
                    
                    使用TypeScript的每日构建版本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../wiki/">
            
                <a href="../wiki/">
            
                    
                    Wiki
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../wiki/this-in-TypeScript.html">
            
                <a href="../wiki/this-in-TypeScript.html">
            
                    
                    TypeScript里的this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../wiki/coding_guidelines.html">
            
                <a href="../wiki/coding_guidelines.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../wiki/Common Errors.html">
            
                <a href="../wiki/Common Errors.html">
            
                    
                    常见编译错误
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../wiki/TypeScript-Editor-Support.html">
            
                <a href="../wiki/TypeScript-Editor-Support.html">
            
                    
                    支持TypeScript的编辑器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                <a href="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                    
                    结合ASP.NET v5使用TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../wiki/Architectural-Overview.html">
            
                <a href="../wiki/Architectural-Overview.html">
            
                    
                    架构概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../wiki/Roadmap.html">
            
                <a href="../wiki/Roadmap.html">
            
                    
                    发展路线图
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../release-notes/">
            
                <a href="../release-notes/">
            
                    
                    新增功能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../release-notes/TypeScript 3.1.html">
            
                <a href="../release-notes/TypeScript 3.1.html">
            
                    
                    TypeScript 3.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../release-notes/TypeScript 3.0.html">
            
                <a href="../release-notes/TypeScript 3.0.html">
            
                    
                    TypeScript 3.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../release-notes/TypeScript 2.9.html">
            
                <a href="../release-notes/TypeScript 2.9.html">
            
                    
                    TypeScript 2.9
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../release-notes/TypeScript 2.8.html">
            
                <a href="../release-notes/TypeScript 2.8.html">
            
                    
                    TypeScript 2.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../release-notes/TypeScript 2.7.html">
            
                <a href="../release-notes/TypeScript 2.7.html">
            
                    
                    TypeScript 2.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../release-notes/TypeScript 2.6.html">
            
                <a href="../release-notes/TypeScript 2.6.html">
            
                    
                    TypeScript 2.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../release-notes/TypeScript 2.5.html">
            
                <a href="../release-notes/TypeScript 2.5.html">
            
                    
                    TypeScript 2.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../release-notes/TypeScript 2.4.html">
            
                <a href="../release-notes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../release-notes/TypeScript 2.3.html">
            
                <a href="../release-notes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../release-notes/TypeScript 2.2.html">
            
                <a href="../release-notes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.11" data-path="../release-notes/TypeScript 2.1.html">
            
                <a href="../release-notes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.12" data-path="../release-notes/TypeScript 2.0.html">
            
                <a href="../release-notes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.13" data-path="../release-notes/TypeScript 1.8.html">
            
                <a href="../release-notes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.14" data-path="../release-notes/TypeScript 1.7.html">
            
                <a href="../release-notes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.15" data-path="../release-notes/TypeScript 1.6.html">
            
                <a href="../release-notes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.16" data-path="../release-notes/TypeScript 1.5.html">
            
                <a href="../release-notes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.17" data-path="../release-notes/TypeScript 1.4.html">
            
                <a href="../release-notes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.18" data-path="../release-notes/TypeScript 1.3.html">
            
                <a href="../release-notes/TypeScript 1.3.html">
            
                    
                    TypeScript 1.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.19" data-path="../release-notes/TypeScript 1.1.html">
            
                <a href="../release-notes/TypeScript 1.1.html">
            
                    
                    TypeScript 1.1
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../breaking-changes/breaking-changes.html">
            
                <a href="../breaking-changes/breaking-changes.html">
            
                    
                    Breaking Changes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../breaking-changes/TypeScript 2.4.html">
            
                <a href="../breaking-changes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../breaking-changes/TypeScript 2.3.html">
            
                <a href="../breaking-changes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../breaking-changes/TypeScript 2.2.html">
            
                <a href="../breaking-changes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../breaking-changes/TypeScript 2.1.html">
            
                <a href="../breaking-changes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../breaking-changes/TypeScript 2.0.html">
            
                <a href="../breaking-changes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../breaking-changes/TypeScript 1.8.html">
            
                <a href="../breaking-changes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../breaking-changes/TypeScript 1.7.html">
            
                <a href="../breaking-changes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../breaking-changes/TypeScript 1.6.html">
            
                <a href="../breaking-changes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../breaking-changes/TypeScript 1.5.html">
            
                <a href="../breaking-changes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="../breaking-changes/TypeScript 1.4.html">
            
                <a href="../breaking-changes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >声明合并</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x4ECB;&#x7ECD;">&#x4ECB;&#x7ECD;</h1>
<p>TypeScript&#x4E2D;&#x6709;&#x4E9B;&#x72EC;&#x7279;&#x7684;&#x6982;&#x5FF5;&#x53EF;&#x4EE5;&#x5728;&#x7C7B;&#x578B;&#x5C42;&#x9762;&#x4E0A;&#x63CF;&#x8FF0;JavaScript&#x5BF9;&#x8C61;&#x7684;&#x6A21;&#x578B;&#x3002;
&#x8FD9;&#x5176;&#x4E2D;&#x5C24;&#x5176;&#x72EC;&#x7279;&#x7684;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x662F;&#x201C;&#x58F0;&#x660E;&#x5408;&#x5E76;&#x201D;&#x7684;&#x6982;&#x5FF5;&#x3002;
&#x7406;&#x89E3;&#x4E86;&#x8FD9;&#x4E2A;&#x6982;&#x5FF5;&#xFF0C;&#x5C06;&#x6709;&#x52A9;&#x4E8E;&#x64CD;&#x4F5C;&#x73B0;&#x6709;&#x7684;JavaScript&#x4EE3;&#x7801;&#x3002;
&#x540C;&#x65F6;&#xFF0C;&#x4E5F;&#x4F1A;&#x6709;&#x52A9;&#x4E8E;&#x7406;&#x89E3;&#x66F4;&#x591A;&#x9AD8;&#x7EA7;&#x62BD;&#x8C61;&#x7684;&#x6982;&#x5FF5;&#x3002;</p>
<p>&#x5BF9;&#x672C;&#x6587;&#x4EF6;&#x6765;&#x8BB2;&#xFF0C;&#x201C;&#x58F0;&#x660E;&#x5408;&#x5E76;&#x201D;&#x662F;&#x6307;&#x7F16;&#x8BD1;&#x5668;&#x5C06;&#x9488;&#x5BF9;&#x540C;&#x4E00;&#x4E2A;&#x540D;&#x5B57;&#x7684;&#x4E24;&#x4E2A;&#x72EC;&#x7ACB;&#x58F0;&#x660E;&#x5408;&#x5E76;&#x4E3A;&#x5355;&#x4E00;&#x58F0;&#x660E;&#x3002;
&#x5408;&#x5E76;&#x540E;&#x7684;&#x58F0;&#x660E;&#x540C;&#x65F6;&#x62E5;&#x6709;&#x539F;&#x5148;&#x4E24;&#x4E2A;&#x58F0;&#x660E;&#x7684;&#x7279;&#x6027;&#x3002;
&#x4EFB;&#x4F55;&#x6570;&#x91CF;&#x7684;&#x58F0;&#x660E;&#x90FD;&#x53EF;&#x88AB;&#x5408;&#x5E76;&#xFF1B;&#x4E0D;&#x5C40;&#x9650;&#x4E8E;&#x4E24;&#x4E2A;&#x58F0;&#x660E;&#x3002;</p>
<h1 id="&#x57FA;&#x7840;&#x6982;&#x5FF5;">&#x57FA;&#x7840;&#x6982;&#x5FF5;</h1>
<p>TypeScript&#x4E2D;&#x7684;&#x58F0;&#x660E;&#x4F1A;&#x521B;&#x5EFA;&#x4EE5;&#x4E0B;&#x4E09;&#x79CD;&#x5B9E;&#x4F53;&#x4E4B;&#x4E00;&#xFF1A;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF0C;&#x7C7B;&#x578B;&#x6216;&#x503C;&#x3002;
&#x521B;&#x5EFA;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x58F0;&#x660E;&#x4F1A;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF0C;&#x5B83;&#x5305;&#x542B;&#x4E86;&#x7528;&#xFF08;.&#xFF09;&#x7B26;&#x53F7;&#x6765;&#x8BBF;&#x95EE;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x540D;&#x5B57;&#x3002;
&#x521B;&#x5EFA;&#x7C7B;&#x578B;&#x7684;&#x58F0;&#x660E;&#x662F;&#xFF1A;&#x7528;&#x58F0;&#x660E;&#x7684;&#x6A21;&#x578B;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7C7B;&#x578B;&#x5E76;&#x7ED1;&#x5B9A;&#x5230;&#x7ED9;&#x5B9A;&#x7684;&#x540D;&#x5B57;&#x4E0A;&#x3002;
&#x6700;&#x540E;&#xFF0C;&#x521B;&#x5EFA;&#x503C;&#x7684;&#x58F0;&#x660E;&#x4F1A;&#x521B;&#x5EFA;&#x5728;JavaScript&#x8F93;&#x51FA;&#x4E2D;&#x770B;&#x5230;&#x7684;&#x503C;&#x3002;</p>
<table>
<thead>
<tr>
<th>Declaration Type</th>
<th style="text-align:center">Namespace</th>
<th style="text-align:center">Type</th>
<th style="text-align:center">Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Namespace</td>
<td style="text-align:center">X</td>
<td style="text-align:center"></td>
<td style="text-align:center">X</td>
</tr>
<tr>
<td>Class</td>
<td style="text-align:center"></td>
<td style="text-align:center">X</td>
<td style="text-align:center">X</td>
</tr>
<tr>
<td>Enum</td>
<td style="text-align:center"></td>
<td style="text-align:center">X</td>
<td style="text-align:center">X</td>
</tr>
<tr>
<td>Interface</td>
<td style="text-align:center"></td>
<td style="text-align:center">X</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td>Type Alias</td>
<td style="text-align:center"></td>
<td style="text-align:center">X</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td>Function</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
<td style="text-align:center">X</td>
</tr>
<tr>
<td>Variable</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
<td style="text-align:center">X</td>
</tr>
</tbody>
</table>
<p>&#x7406;&#x89E3;&#x6BCF;&#x4E2A;&#x58F0;&#x660E;&#x521B;&#x5EFA;&#x4E86;&#x4EC0;&#x4E48;&#xFF0C;&#x6709;&#x52A9;&#x4E8E;&#x7406;&#x89E3;&#x5F53;&#x58F0;&#x660E;&#x5408;&#x5E76;&#x65F6;&#x6709;&#x54EA;&#x4E9B;&#x4E1C;&#x897F;&#x88AB;&#x5408;&#x5E76;&#x4E86;&#x3002;</p>
<h1 id="&#x5408;&#x5E76;&#x63A5;&#x53E3;">&#x5408;&#x5E76;&#x63A5;&#x53E3;</h1>
<p>&#x6700;&#x7B80;&#x5355;&#x4E5F;&#x6700;&#x5E38;&#x89C1;&#x7684;&#x58F0;&#x660E;&#x5408;&#x5E76;&#x7C7B;&#x578B;&#x662F;&#x63A5;&#x53E3;&#x5408;&#x5E76;&#x3002;
&#x4ECE;&#x6839;&#x672C;&#x4E0A;&#x8BF4;&#xFF0C;&#x5408;&#x5E76;&#x7684;&#x673A;&#x5236;&#x662F;&#x628A;&#x53CC;&#x65B9;&#x7684;&#x6210;&#x5458;&#x653E;&#x5230;&#x4E00;&#x4E2A;&#x540C;&#x540D;&#x7684;&#x63A5;&#x53E3;&#x91CC;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> Box {
    height: <span class="hljs-built_in">number</span>;
    width: <span class="hljs-built_in">number</span>;
}

<span class="hljs-keyword">interface</span> Box {
    scale: <span class="hljs-built_in">number</span>;
}

<span class="hljs-keyword">let</span> box: Box = {height: <span class="hljs-number">5</span>, width: <span class="hljs-number">6</span>, scale: <span class="hljs-number">10</span>};
</code></pre>
<p>&#x63A5;&#x53E3;&#x7684;&#x975E;&#x51FD;&#x6570;&#x7684;&#x6210;&#x5458;&#x5E94;&#x8BE5;&#x662F;&#x552F;&#x4E00;&#x7684;&#x3002;
&#x5982;&#x679C;&#x5B83;&#x4EEC;&#x4E0D;&#x662F;&#x552F;&#x4E00;&#x7684;&#xFF0C;&#x90A3;&#x4E48;&#x5B83;&#x4EEC;&#x5FC5;&#x987B;&#x662F;&#x76F8;&#x540C;&#x7684;&#x7C7B;&#x578B;&#x3002;
&#x5982;&#x679C;&#x4E24;&#x4E2A;&#x63A5;&#x53E3;&#x4E2D;&#x540C;&#x65F6;&#x58F0;&#x660E;&#x4E86;&#x540C;&#x540D;&#x7684;&#x975E;&#x51FD;&#x6570;&#x6210;&#x5458;&#x4E14;&#x5B83;&#x4EEC;&#x7684;&#x7C7B;&#x578B;&#x4E0D;&#x540C;&#xFF0C;&#x5219;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x51FD;&#x6570;&#x6210;&#x5458;&#xFF0C;&#x6BCF;&#x4E2A;&#x540C;&#x540D;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x90FD;&#x4F1A;&#x88AB;&#x5F53;&#x6210;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x7684;&#x4E00;&#x4E2A;&#x91CD;&#x8F7D;&#x3002;
&#x540C;&#x65F6;&#x9700;&#x8981;&#x6CE8;&#x610F;&#xFF0C;&#x5F53;&#x63A5;&#x53E3;<code>A</code>&#x4E0E;&#x540E;&#x6765;&#x7684;&#x63A5;&#x53E3;<code>A</code>&#x5408;&#x5E76;&#x65F6;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x63A5;&#x53E3;&#x5177;&#x6709;&#x66F4;&#x9AD8;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#x3002;</p>
<p>&#x5982;&#x4E0B;&#x4F8B;&#x6240;&#x793A;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> Cloner {
    clone(animal: Animal): Animal;
}

<span class="hljs-keyword">interface</span> Cloner {
    clone(animal: Sheep): Sheep;
}

<span class="hljs-keyword">interface</span> Cloner {
    clone(animal: Dog): Dog;
    clone(animal: Cat): Cat;
}
</code></pre>
<p>&#x8FD9;&#x4E09;&#x4E2A;&#x63A5;&#x53E3;&#x5408;&#x5E76;&#x6210;&#x4E00;&#x4E2A;&#x58F0;&#x660E;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> Cloner {
    clone(animal: Dog): Dog;
    clone(animal: Cat): Cat;
    clone(animal: Sheep): Sheep;
    clone(animal: Animal): Animal;
}
</code></pre>
<p>&#x6CE8;&#x610F;&#x6BCF;&#x7EC4;&#x63A5;&#x53E3;&#x91CC;&#x7684;&#x58F0;&#x660E;&#x987A;&#x5E8F;&#x4FDD;&#x6301;&#x4E0D;&#x53D8;&#xFF0C;&#x4F46;&#x5404;&#x7EC4;&#x63A5;&#x53E3;&#x4E4B;&#x95F4;&#x7684;&#x987A;&#x5E8F;&#x662F;&#x540E;&#x6765;&#x7684;&#x63A5;&#x53E3;&#x91CD;&#x8F7D;&#x51FA;&#x73B0;&#x5728;&#x9760;&#x524D;&#x4F4D;&#x7F6E;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x89C4;&#x5219;&#x6709;&#x4E00;&#x4E2A;&#x4F8B;&#x5916;&#x662F;&#x5F53;&#x51FA;&#x73B0;&#x7279;&#x6B8A;&#x7684;&#x51FD;&#x6570;&#x7B7E;&#x540D;&#x65F6;&#x3002;
&#x5982;&#x679C;&#x7B7E;&#x540D;&#x91CC;&#x6709;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x7C7B;&#x578B;&#x662F;<em>&#x5355;&#x4E00;</em>&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x5B57;&#x9762;&#x91CF;&#xFF08;&#x6BD4;&#x5982;&#xFF0C;&#x4E0D;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x5B57;&#x9762;&#x91CF;&#x7684;&#x8054;&#x5408;&#x7C7B;&#x578B;&#xFF09;&#xFF0C;&#x90A3;&#x4E48;&#x5B83;&#x5C06;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#x5230;&#x91CD;&#x8F7D;&#x5217;&#x8868;&#x7684;&#x6700;&#x9876;&#x7AEF;&#x3002;</p>
<p>&#x6BD4;&#x5982;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x63A5;&#x53E3;&#x4F1A;&#x5408;&#x5E76;&#x5230;&#x4E00;&#x8D77;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> Document {
    createElement(tagName: <span class="hljs-built_in">any</span>): Element;
}
<span class="hljs-keyword">interface</span> Document {
    createElement(tagName: <span class="hljs-string">&quot;div&quot;</span>): HTMLDivElement;
    createElement(tagName: <span class="hljs-string">&quot;span&quot;</span>): HTMLSpanElement;
}
<span class="hljs-keyword">interface</span> Document {
    createElement(tagName: <span class="hljs-built_in">string</span>): HTMLElement;
    createElement(tagName: <span class="hljs-string">&quot;canvas&quot;</span>): HTMLCanvasElement;
}
</code></pre>
<p>&#x5408;&#x5E76;&#x540E;&#x7684;<code>Document</code>&#x5C06;&#x4F1A;&#x50CF;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> Document {
    createElement(tagName: <span class="hljs-string">&quot;canvas&quot;</span>): HTMLCanvasElement;
    createElement(tagName: <span class="hljs-string">&quot;div&quot;</span>): HTMLDivElement;
    createElement(tagName: <span class="hljs-string">&quot;span&quot;</span>): HTMLSpanElement;
    createElement(tagName: <span class="hljs-built_in">string</span>): HTMLElement;
    createElement(tagName: <span class="hljs-built_in">any</span>): Element;
}
</code></pre>
<h1 id="&#x5408;&#x5E76;&#x547D;&#x540D;&#x7A7A;&#x95F4;">&#x5408;&#x5E76;&#x547D;&#x540D;&#x7A7A;&#x95F4;</h1>
<p>&#x4E0E;&#x63A5;&#x53E3;&#x76F8;&#x4F3C;&#xFF0C;&#x540C;&#x540D;&#x7684;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x4E5F;&#x4F1A;&#x5408;&#x5E76;&#x5176;&#x6210;&#x5458;&#x3002;
&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x4F1A;&#x521B;&#x5EFA;&#x51FA;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x548C;&#x503C;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x77E5;&#x9053;&#x8FD9;&#x4E24;&#x8005;&#x90FD;&#x662F;&#x600E;&#x4E48;&#x5408;&#x5E76;&#x7684;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x5408;&#x5E76;&#xFF0C;&#x6A21;&#x5757;&#x5BFC;&#x51FA;&#x7684;&#x540C;&#x540D;&#x63A5;&#x53E3;&#x8FDB;&#x884C;&#x5408;&#x5E76;&#xFF0C;&#x6784;&#x6210;&#x5355;&#x4E00;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5185;&#x542B;&#x5408;&#x5E76;&#x540E;&#x7684;&#x63A5;&#x53E3;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x91CC;&#x503C;&#x7684;&#x5408;&#x5E76;&#xFF0C;&#x5982;&#x679C;&#x5F53;&#x524D;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7ED9;&#x5B9A;&#x540D;&#x5B57;&#x7684;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF0C;&#x90A3;&#x4E48;&#x540E;&#x6765;&#x7684;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x5BFC;&#x51FA;&#x6210;&#x5458;&#x4F1A;&#x88AB;&#x52A0;&#x5230;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x90A3;&#x4E2A;&#x6A21;&#x5757;&#x91CC;&#x3002;</p>
<p><code>Animals</code>&#x58F0;&#x660E;&#x5408;&#x5E76;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">namespace</span> Animals {
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Zebra { }
}

<span class="hljs-keyword">namespace</span> Animals {
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> Legged { numberOfLegs: <span class="hljs-built_in">number</span>; }
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Dog { }
}
</code></pre>
<p>&#x7B49;&#x540C;&#x4E8E;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">namespace</span> Animals {
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> Legged { numberOfLegs: <span class="hljs-built_in">number</span>; }

    <span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Zebra { }
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Dog { }
}
</code></pre>
<p>&#x9664;&#x4E86;&#x8FD9;&#x4E9B;&#x5408;&#x5E76;&#x5916;&#xFF0C;&#x4F60;&#x8FD8;&#x9700;&#x8981;&#x4E86;&#x89E3;&#x975E;&#x5BFC;&#x51FA;&#x6210;&#x5458;&#x662F;&#x5982;&#x4F55;&#x5904;&#x7406;&#x7684;&#x3002;
&#x975E;&#x5BFC;&#x51FA;&#x6210;&#x5458;&#x4EC5;&#x5728;&#x5176;&#x539F;&#x6709;&#x7684;&#xFF08;&#x5408;&#x5E76;&#x524D;&#x7684;&#xFF09;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5185;&#x53EF;&#x89C1;&#x3002;&#x8FD9;&#x5C31;&#x662F;&#x8BF4;&#x5408;&#x5E76;&#x4E4B;&#x540E;&#xFF0C;&#x4ECE;&#x5176;&#x5B83;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5408;&#x5E76;&#x8FDB;&#x6765;&#x7684;&#x6210;&#x5458;&#x65E0;&#x6CD5;&#x8BBF;&#x95EE;&#x975E;&#x5BFC;&#x51FA;&#x6210;&#x5458;&#x3002;</p>
<p>&#x4E0B;&#x4F8B;&#x63D0;&#x4F9B;&#x4E86;&#x66F4;&#x6E05;&#x6670;&#x7684;&#x8BF4;&#x660E;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">namespace</span> Animal {
    <span class="hljs-keyword">let</span> haveMuscles = <span class="hljs-literal">true</span>;

    <span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">animalsHaveMuscles</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">return</span> haveMuscles;
    }
}

<span class="hljs-keyword">namespace</span> Animal {
    <span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">doAnimalsHaveMuscles</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">return</span> haveMuscles;  <span class="hljs-comment">// Error, because haveMuscles is not accessible here</span>
    }
}
</code></pre>
<p>&#x56E0;&#x4E3A;<code>haveMuscles</code>&#x5E76;&#x6CA1;&#x6709;&#x5BFC;&#x51FA;&#xFF0C;&#x53EA;&#x6709;<code>animalsHaveMuscles</code>&#x51FD;&#x6570;&#x5171;&#x4EAB;&#x4E86;&#x539F;&#x59CB;&#x672A;&#x5408;&#x5E76;&#x7684;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x3002;
<code>doAnimalsHaveMuscles</code>&#x51FD;&#x6570;&#x867D;&#x662F;&#x5408;&#x5E76;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x4E00;&#x90E8;&#x5206;&#xFF0C;&#x4F46;&#x662F;&#x8BBF;&#x95EE;&#x4E0D;&#x4E86;&#x672A;&#x5BFC;&#x51FA;&#x7684;&#x6210;&#x5458;&#x3002;</p>
<h1 id="&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x4E0E;&#x7C7B;&#x548C;&#x51FD;&#x6570;&#x548C;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x5408;&#x5E76;">&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x4E0E;&#x7C7B;&#x548C;&#x51FD;&#x6570;&#x548C;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x5408;&#x5E76;</h1>
<p>&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x53EF;&#x4EE5;&#x4E0E;&#x5176;&#x5B83;&#x7C7B;&#x578B;&#x7684;&#x58F0;&#x660E;&#x8FDB;&#x884C;&#x5408;&#x5E76;&#x3002;
&#x53EA;&#x8981;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x5B9A;&#x4E49;&#x7B26;&#x5408;&#x5C06;&#x8981;&#x5408;&#x5E76;&#x7C7B;&#x578B;&#x7684;&#x5B9A;&#x4E49;&#x3002;&#x5408;&#x5E76;&#x7ED3;&#x679C;&#x5305;&#x542B;&#x4E24;&#x8005;&#x7684;&#x58F0;&#x660E;&#x7C7B;&#x578B;&#x3002;
TypeScript&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x529F;&#x80FD;&#x53BB;&#x5B9E;&#x73B0;&#x4E00;&#x4E9B;JavaScript&#x91CC;&#x7684;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x3002;</p>
<h2 id="&#x5408;&#x5E76;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x548C;&#x7C7B;">&#x5408;&#x5E76;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x548C;&#x7C7B;</h2>
<p>&#x8FD9;&#x8BA9;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8868;&#x793A;&#x5185;&#x90E8;&#x7C7B;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">class</span> Album {
    label: Album.AlbumLabel;
}
<span class="hljs-keyword">namespace</span> Album {
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> AlbumLabel { }
}
</code></pre>
<p>&#x5408;&#x5E76;&#x89C4;&#x5219;&#x4E0E;&#x4E0A;&#x9762;<code>&#x5408;&#x5E76;&#x547D;&#x540D;&#x7A7A;&#x95F4;</code>&#x5C0F;&#x8282;&#x91CC;&#x8BB2;&#x7684;&#x89C4;&#x5219;&#x4E00;&#x81F4;&#xFF0C;&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x5BFC;&#x51FA;<code>AlbumLabel</code>&#x7C7B;&#xFF0C;&#x597D;&#x8BA9;&#x5408;&#x5E76;&#x7684;&#x7C7B;&#x80FD;&#x8BBF;&#x95EE;&#x3002;
&#x5408;&#x5E76;&#x7ED3;&#x679C;&#x662F;&#x4E00;&#x4E2A;&#x7C7B;&#x5E76;&#x5E26;&#x6709;&#x4E00;&#x4E2A;&#x5185;&#x90E8;&#x7C7B;&#x3002;
&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x4E3A;&#x7C7B;&#x589E;&#x52A0;&#x4E00;&#x4E9B;&#x9759;&#x6001;&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x9664;&#x4E86;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x6A21;&#x5F0F;&#xFF0C;&#x4F60;&#x5728;JavaScript&#x91CC;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x7A0D;&#x540E;&#x6269;&#x5C55;&#x5B83;&#x589E;&#x52A0;&#x4E00;&#x4E9B;&#x5C5E;&#x6027;&#x4E5F;&#x662F;&#x5F88;&#x5E38;&#x89C1;&#x7684;&#x3002;
TypeScript&#x4F7F;&#x7528;&#x58F0;&#x660E;&#x5408;&#x5E76;&#x6765;&#x8FBE;&#x5230;&#x8FD9;&#x4E2A;&#x76EE;&#x7684;&#x5E76;&#x4FDD;&#x8BC1;&#x7C7B;&#x578B;&#x5B89;&#x5168;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">buildLabel</span>(<span class="hljs-params">name: <span class="hljs-built_in">string</span></span>): <span class="hljs-title">string</span> </span>{
    <span class="hljs-keyword">return</span> buildLabel.prefix + name + buildLabel.suffix;
}

<span class="hljs-keyword">namespace</span> buildLabel {
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">let</span> suffix = <span class="hljs-string">&quot;&quot;</span>;
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">let</span> prefix = <span class="hljs-string">&quot;Hello, &quot;</span>;
}

<span class="hljs-built_in">console</span>.log(buildLabel(<span class="hljs-string">&quot;Sam Smith&quot;</span>));
</code></pre>
<p>&#x76F8;&#x4F3C;&#x7684;&#xFF0C;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x6269;&#x5C55;&#x679A;&#x4E3E;&#x578B;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> Color {
    red = <span class="hljs-number">1</span>,
    green = <span class="hljs-number">2</span>,
    blue = <span class="hljs-number">4</span>
}

<span class="hljs-keyword">namespace</span> Color {
    <span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mixColor</span>(<span class="hljs-params">colorName: <span class="hljs-built_in">string</span></span>) </span>{
        <span class="hljs-keyword">if</span> (colorName == <span class="hljs-string">&quot;yellow&quot;</span>) {
            <span class="hljs-keyword">return</span> Color.red + Color.green;
        }
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (colorName == <span class="hljs-string">&quot;white&quot;</span>) {
            <span class="hljs-keyword">return</span> Color.red + Color.green + Color.blue;
        }
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (colorName == <span class="hljs-string">&quot;magenta&quot;</span>) {
            <span class="hljs-keyword">return</span> Color.red + Color.blue;
        }
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (colorName == <span class="hljs-string">&quot;cyan&quot;</span>) {
            <span class="hljs-keyword">return</span> Color.green + Color.blue;
        }
    }
}
</code></pre>
<h1 id="&#x975E;&#x6CD5;&#x7684;&#x5408;&#x5E76;">&#x975E;&#x6CD5;&#x7684;&#x5408;&#x5E76;</h1>
<p>TypeScript&#x5E76;&#x975E;&#x5141;&#x8BB8;&#x6240;&#x6709;&#x7684;&#x5408;&#x5E76;&#x3002;
&#x76EE;&#x524D;&#xFF0C;&#x7C7B;&#x4E0D;&#x80FD;&#x4E0E;&#x5176;&#x5B83;&#x7C7B;&#x6216;&#x53D8;&#x91CF;&#x5408;&#x5E76;&#x3002;
&#x60F3;&#x8981;&#x4E86;&#x89E3;&#x5982;&#x4F55;&#x6A21;&#x4EFF;&#x7C7B;&#x7684;&#x5408;&#x5E76;&#xFF0C;&#x8BF7;&#x53C2;&#x8003;<a href="Mixins.html">TypeScript&#x7684;&#x6DF7;&#x5165;</a>&#x3002;</p>
<h1 id="&#x6A21;&#x5757;&#x6269;&#x5C55;">&#x6A21;&#x5757;&#x6269;&#x5C55;</h1>
<p>&#x867D;&#x7136;JavaScript&#x4E0D;&#x652F;&#x6301;&#x5408;&#x5E76;&#xFF0C;&#x4F46;&#x4F60;&#x53EF;&#x4EE5;&#x4E3A;&#x5BFC;&#x5165;&#x7684;&#x5BF9;&#x8C61;&#x6253;&#x8865;&#x4E01;&#x4EE5;&#x66F4;&#x65B0;&#x5B83;&#x4EEC;&#x3002;&#x8BA9;&#x6211;&#x4EEC;&#x8003;&#x5BDF;&#x4E00;&#x4E0B;&#x8FD9;&#x4E2A;&#x73A9;&#x5177;&#x6027;&#x7684;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// observable.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Observable</span>&lt;<span class="hljs-title">T</span>&gt; </span>{
    <span class="hljs-comment">// ... implementation left as an exercise for the reader ...</span>
}

<span class="hljs-comment">// map.js</span>
<span class="hljs-keyword">import</span> { Observable } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;./observable&quot;</span>;
Observable.prototype.map = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">f</span>) </span>{
    <span class="hljs-comment">// ... another exercise for the reader</span>
}
</code></pre>
<p>&#x5B83;&#x4E5F;&#x53EF;&#x4EE5;&#x5F88;&#x597D;&#x5730;&#x5DE5;&#x4F5C;&#x5728;TypeScript&#x4E2D;&#xFF0C; &#x4F46;&#x7F16;&#x8BD1;&#x5668;&#x5BF9; <code>Observable.prototype.map</code>&#x4E00;&#x65E0;&#x6240;&#x77E5;&#x3002;
&#x4F60;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x6269;&#x5C55;&#x6A21;&#x5757;&#x6765;&#x5C06;&#x5B83;&#x544A;&#x8BC9;&#x7F16;&#x8BD1;&#x5668;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-comment">// observable.ts stays the same</span>
<span class="hljs-comment">// map.ts</span>
<span class="hljs-keyword">import</span> { Observable } from <span class="hljs-string">&quot;./observable&quot;</span>;
<span class="hljs-keyword">declare</span> <span class="hljs-keyword">module</span> &quot;./observable&quot; {
    <span class="hljs-keyword">interface</span> Observable&lt;T&gt; {
        map&lt;U&gt;(f: (x: T) =&gt; U): Observable&lt;U&gt;;
    }
}
Observable.prototype.map = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">f</span>) </span>{
    <span class="hljs-comment">// ... another exercise for the reader</span>
}


<span class="hljs-comment">// consumer.ts</span>
<span class="hljs-keyword">import</span> { Observable } from <span class="hljs-string">&quot;./observable&quot;</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;./map&quot;</span>;
<span class="hljs-keyword">let</span> o: Observable&lt;<span class="hljs-built_in">number</span>&gt;;
o.map(x =&gt; x.toFixed());
</code></pre>
<p>&#x6A21;&#x5757;&#x540D;&#x7684;&#x89E3;&#x6790;&#x548C;&#x7528;<code>import</code>/<code>export</code>&#x89E3;&#x6790;&#x6A21;&#x5757;&#x6807;&#x8BC6;&#x7B26;&#x7684;&#x65B9;&#x5F0F;&#x662F;&#x4E00;&#x81F4;&#x7684;&#x3002;
&#x66F4;&#x591A;&#x4FE1;&#x606F;&#x8BF7;&#x53C2;&#x8003; <a href="Modules.html">Modules</a>&#x3002;
&#x5F53;&#x8FD9;&#x4E9B;&#x58F0;&#x660E;&#x5728;&#x6269;&#x5C55;&#x4E2D;&#x5408;&#x5E76;&#x65F6;&#xFF0C;&#x5C31;&#x597D;&#x50CF;&#x5728;&#x539F;&#x59CB;&#x4F4D;&#x7F6E;&#x88AB;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x6837;&#x3002;
&#x4F46;&#x662F;&#xFF0C;&#x4F60;&#x4E0D;&#x80FD;&#x5728;&#x6269;&#x5C55;&#x4E2D;&#x58F0;&#x660E;&#x65B0;&#x7684;&#x9876;&#x7EA7;&#x58F0;&#x660E;&#xFF0D;&#x4EC5;&#x53EF;&#x4EE5;&#x6269;&#x5C55;&#x6A21;&#x5757;&#x4E2D;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x58F0;&#x660E;&#x3002;</p>
<h2 id="&#x5168;&#x5C40;&#x6269;&#x5C55;">&#x5168;&#x5C40;&#x6269;&#x5C55;</h2>
<p>&#x4F60;&#x4E5F;&#x4EE5;&#x5728;&#x6A21;&#x5757;&#x5185;&#x90E8;&#x6DFB;&#x52A0;&#x58F0;&#x660E;&#x5230;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x4E2D;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-comment">// observable.ts</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Observable&lt;T&gt; {
    <span class="hljs-comment">// ... still no implementation ...</span>
}

<span class="hljs-keyword">declare</span> global {
    <span class="hljs-keyword">interface</span> Array&lt;T&gt; {
        toObservable(): Observable&lt;T&gt;;
    }
}

<span class="hljs-built_in">Array</span>.prototype.toObservable = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// ...</span>
}
</code></pre>
<p>&#x5168;&#x5C40;&#x6269;&#x5C55;&#x4E0E;&#x6A21;&#x5757;&#x6269;&#x5C55;&#x7684;&#x884C;&#x4E3A;&#x548C;&#x9650;&#x5236;&#x662F;&#x76F8;&#x540C;&#x7684;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Module Resolution.html" class="navigation navigation-prev " aria-label="Previous page: 模块解析">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Writing Definition Files.html" class="navigation navigation-next " aria-label="Next page: 书写.d.ts文件">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"声明合并","level":"1.3.18","depth":2,"next":{"title":"书写.d.ts文件","level":"1.3.19","depth":2,"path":"doc/handbook/Writing Definition Files.md","ref":"./doc/handbook/Writing Definition Files.md","articles":[]},"previous":{"title":"模块解析","level":"1.3.17","depth":2,"path":"doc/handbook/Module Resolution.md","ref":"./doc/handbook/Module Resolution.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Patrick Zhong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"preface.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"TypeScript Handbook","language":"zh-hans","gitbook":">3.0.0","description":"Translation of official TypeScript Handbook"},"file":{"path":"doc/handbook/Declaration Merging.md","mtime":"2018-10-13T09:48:54.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T09:57:42.904Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

